
# Set and run scripts ----
rm(list = ls())
gc()

library(tidyverse)

setwd("")

set.seed(123)

source("rcs_climat.R")
source("rcs_ocde.R")
source("rcs_prop26.R")
source("rcs_prop27.R")


# Appendix B2 ----
sumfit_climat
sumfit_OCDE
sumfit_prop26
sumfit_prop27


# Figure 3 ----

med_summary <- data.frame(matrix(ncol = 7, nrow = 8))
x <- c("effect", "ind", "lowind", "uppind", "dir", "lowdir", "uppdir")
colnames(med_summary) <- x

# Outcome = vote inline party cue
med_summary[1,1] <- "Climate : Time > knowledge party cue > vote inline"
med_summary[1,2] <- sumfit_climat_df[sumfit_climat_df$label == "days_cue_inline", 6]
med_summary[1,3] <- sumfit_climat_df[sumfit_climat_df$label == "days_cue_inline", 10]
med_summary[1,4] <- sumfit_climat_df[sumfit_climat_df$label == "days_cue_inline", 11]
med_summary[1,5] <- sumfit_climat_df[sumfit_climat_df$label == "c1", 6]
med_summary[1,6] <- sumfit_climat_df[sumfit_climat_df$label == "c1", 10]
med_summary[1,7] <- sumfit_climat_df[sumfit_climat_df$label == "c1", 11]

med_summary[2,1] <- "OECD : Time > knowledge party cue > vote inline"
med_summary[2,2] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "days_cue_inline", 6]
med_summary[2,3] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "days_cue_inline", 10]
med_summary[2,4] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "days_cue_inline", 11]
med_summary[2,5] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "c1", 6]
med_summary[2,6] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "c1", 10]
med_summary[2,7] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "c1", 11]

med_summary[3,1] <- "Proposition 26 : Time > knowledge party cue > vote inline"
med_summary[3,2] <- sumfit_prop26_df[sumfit_prop26_df$label == "days_cue_inline", 6]
med_summary[3,3] <- sumfit_prop26_df[sumfit_prop26_df$label == "days_cue_inline", 10]
med_summary[3,4] <- sumfit_prop26_df[sumfit_prop26_df$label == "days_cue_inline", 11]
med_summary[3,5] <- sumfit_prop26_df[sumfit_prop26_df$label == "c1", 6]
med_summary[3,6] <- sumfit_prop26_df[sumfit_prop26_df$label == "c1", 10]
med_summary[3,7] <- sumfit_prop26_df[sumfit_prop26_df$label == "c1", 11]

med_summary[4,1] <- "Proposition 27 : Time > knowledge party cue > vote inline"
med_summary[4,2] <- sumfit_prop27_df[sumfit_prop27_df$label == "days_cue_inline", 6]
med_summary[4,3] <- sumfit_prop27_df[sumfit_prop27_df$label == "days_cue_inline", 10]
med_summary[4,4] <- sumfit_prop27_df[sumfit_prop27_df$label == "days_cue_inline", 11]
med_summary[4,5] <- sumfit_prop27_df[sumfit_prop27_df$label == "c1", 6]
med_summary[4,6] <- sumfit_prop27_df[sumfit_prop27_df$label == "c1", 10]
med_summary[4,7] <- sumfit_prop27_df[sumfit_prop27_df$label == "c1", 11]


# Outcome = consistent voting
med_summary[5,1] <- "Climate : Time > DKs arguments > consistent vote"
med_summary[5,2] <- sumfit_climat_df[sumfit_climat_df$label == "days_dk_cons", 6]
med_summary[5,3] <- sumfit_climat_df[sumfit_climat_df$label == "days_dk_cons", 10]
med_summary[5,4] <- sumfit_climat_df[sumfit_climat_df$label == "days_dk_cons", 11]
med_summary[5,5] <- sumfit_climat_df[sumfit_climat_df$label == "c2", 6]
med_summary[5,6] <- sumfit_climat_df[sumfit_climat_df$label == "c2", 10]
med_summary[5,7] <- sumfit_climat_df[sumfit_climat_df$label == "c2", 11]

med_summary[6,1] <- "OECD : Time > DKs arguments > consistent vote"
med_summary[6,2] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "days_dk_cons", 6]
med_summary[6,3] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "days_dk_cons", 10]
med_summary[6,4] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "days_dk_cons", 11]
med_summary[6,5] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "c2", 6]
med_summary[6,6] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "c2", 10]
med_summary[6,7] <- sumfit_OCDE_df[sumfit_OCDE_df$label == "c2", 11]

med_summary[7,1] <- "Proposition 26 : Time > DKs arguments > consistent vote"
med_summary[7,2] <- sumfit_prop26_df[sumfit_prop26_df$label == "days_dk_cons", 6]
med_summary[7,3] <- sumfit_prop26_df[sumfit_prop26_df$label == "days_dk_cons", 10]
med_summary[7,4] <- sumfit_prop26_df[sumfit_prop26_df$label == "days_dk_cons", 11]
med_summary[7,5] <- sumfit_prop26_df[sumfit_prop26_df$label == "c2", 6]
med_summary[7,6] <- sumfit_prop26_df[sumfit_prop26_df$label == "c2", 10]
med_summary[7,7] <- sumfit_prop26_df[sumfit_prop26_df$label == "c2", 11]

med_summary[8,1] <- "Proposition 27 : Time > DKs arguments > consistent vote"
med_summary[8,2] <- sumfit_prop27_df[sumfit_prop27_df$label == "days_dk_cons", 6]
med_summary[8,3] <- sumfit_prop27_df[sumfit_prop27_df$label == "days_dk_cons", 10]
med_summary[8,4] <- sumfit_prop27_df[sumfit_prop27_df$label == "days_dk_cons", 11]
med_summary[8,5] <- sumfit_prop27_df[sumfit_prop27_df$label == "c2", 6]
med_summary[8,6] <- sumfit_prop27_df[sumfit_prop27_df$label == "c2", 10]
med_summary[8,7] <- sumfit_prop27_df[sumfit_prop27_df$label == "c2", 11]

med_summary


# Indirect
ind <- med_summary %>% dplyr::select(1:4)
glimpse(ind)

empty_row <- data.frame(effect = "", ind = NA, lowind = NA, uppind = NA)
ind <- rbind(ind[1:4, ], empty_row, ind[5:nrow(ind), ])
rownames(ind) <- NULL

ind

ind$effect <- factor(ind$effect, 
                      levels = c("Proposition 27 : Time > DKs arguments > consistent vote",
                                 "Proposition 26 : Time > DKs arguments > consistent vote",
                                 "OECD : Time > DKs arguments > consistent vote",
                                 "Climate : Time > DKs arguments > consistent vote",
                                 "",
                                 "Proposition 27 : Time > knowledge party cue > vote inline", 
                                 "Proposition 26 : Time > knowledge party cue > vote inline",
                                 "OECD : Time > knowledge party cue > vote inline",
                                 "Climate : Time > knowledge party cue > vote inline"),
                      ordered = T)

ind_plot <- ggplot(ind, aes(x = effect, y = ind)) + 
  geom_pointrange(aes(ymin = lowind, ymax = uppind), size = 0.25) +
  scale_y_continuous(limits = c(-0.06,0.45), breaks = seq(-0.05, 0.40, by = 0.10)) +
  geom_hline(yintercept = 0) +
  xlab("") + ylab("Estimate") + ggtitle("Indirect effects") +
  theme_minimal() +
  coord_flip()  

ind_plot

ggsave("fig3indirect.png", scale = 1, width = 18, height = 10, units = "cm", dpi = 600)



# Direct

dir <- med_summary %>% dplyr::select(c(1,5,6,7))
dir

empty_row <- data.frame(effect = "", dir = NA, lowdir = NA, uppdir = NA)
dir <- rbind(dir[1:4, ], empty_row, dir[5:nrow(dir), ])
rownames(dir) <- NULL

dir$effect <- factor(dir$effect, 
                     levels = c("Proposition 27 : Time > DKs arguments > consistent vote",
                                "Proposition 26 : Time > DKs arguments > consistent vote",
                                "OECD : Time > DKs arguments > consistent vote",
                                "Climate : Time > DKs arguments > consistent vote",
                                "",
                                "Proposition 27 : Time > knowledge party cue > vote inline", 
                                "Proposition 26 : Time > knowledge party cue > vote inline",
                                "OECD : Time > knowledge party cue > vote inline",
                                "Climate : Time > knowledge party cue > vote inline"),
                     labels = c("Proposition 27 : Time > consistent vote",
                                "Proposition 26 : Time > consistent vote",
                                "OECD : Time > consistent vote",
                                "Climate : Time > consistent vote",
                                "",
                                "Proposition 27 : Time > vote inline", 
                                "Proposition 26 : Time > vote inline",
                                "OECD : Time > vote inline",
                                "Climate : Time > vote inline"),
                     ordered = T)

dir_plot <- ggplot(dir, aes(x = effect, y = dir)) + 
  geom_pointrange(aes(ymin = lowdir, ymax = uppdir), size = 0.25) +
  scale_y_continuous(limits = c(-0.42,0.68), breaks = seq(-0.40, 0.60, by = 0.10), labels = scales::label_number()) +
  geom_hline(yintercept = 0) +
  xlab("") + ylab("Estimate") + ggtitle("Direct effects") +
  theme_minimal() +
  coord_flip()

dir_plot

ggsave("fig3direct.png", scale = 1, width = 18, height = 10, units = "cm", dpi = 600)





# Appendix C3a ----

# Empty dataframe
med_summary <- data.frame(matrix(ncol = 7, nrow = 8))
x <- c("effect", "ind", "lowind", "uppind", "dir", "lowdir", "uppdir")
colnames(med_summary) <- x

# Outcome = vote inline party cue
med_summary[1,1] <- "Climate : Time > knowledge party cue > vote inline"
med_summary[1,2] <- sumfit_climat0_df[sumfit_climat0_df$label == "days_cue_inline", 6]
med_summary[1,3] <- sumfit_climat0_df[sumfit_climat0_df$label == "days_cue_inline", 10]
med_summary[1,4] <- sumfit_climat0_df[sumfit_climat0_df$label == "days_cue_inline", 11]
med_summary[1,5] <- sumfit_climat0_df[sumfit_climat0_df$label == "c1", 6]
med_summary[1,6] <- sumfit_climat0_df[sumfit_climat0_df$label == "c1", 10]
med_summary[1,7] <- sumfit_climat0_df[sumfit_climat0_df$label == "c1", 11]

med_summary[2,1] <- "OECD : Time > knowledge party cue > vote inline"
med_summary[2,2] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "days_cue_inline", 6]
med_summary[2,3] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "days_cue_inline", 10]
med_summary[2,4] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "days_cue_inline", 11]
med_summary[2,5] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "c1", 6]
med_summary[2,6] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "c1", 10]
med_summary[2,7] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "c1", 11]

med_summary[3,1] <- "Proposition 26 : Time > knowledge party cue > vote inline"
med_summary[3,2] <- sumfit_prop260_df[sumfit_prop260_df$label == "days_cue_inline", 6]
med_summary[3,3] <- sumfit_prop260_df[sumfit_prop260_df$label == "days_cue_inline", 10]
med_summary[3,4] <- sumfit_prop260_df[sumfit_prop260_df$label == "days_cue_inline", 11]
med_summary[3,5] <- sumfit_prop260_df[sumfit_prop260_df$label == "c1", 6]
med_summary[3,6] <- sumfit_prop260_df[sumfit_prop260_df$label == "c1", 10]
med_summary[3,7] <- sumfit_prop260_df[sumfit_prop260_df$label == "c1", 11]

med_summary[4,1] <- "Proposition 27 : Time > knowledge party cue > vote inline"
med_summary[4,2] <- sumfit_prop270_df[sumfit_prop270_df$label == "days_cue_inline", 6]
med_summary[4,3] <- sumfit_prop270_df[sumfit_prop270_df$label == "days_cue_inline", 10]
med_summary[4,4] <- sumfit_prop270_df[sumfit_prop270_df$label == "days_cue_inline", 11]
med_summary[4,5] <- sumfit_prop270_df[sumfit_prop270_df$label == "c1", 6]
med_summary[4,6] <- sumfit_prop270_df[sumfit_prop270_df$label == "c1", 10]
med_summary[4,7] <- sumfit_prop270_df[sumfit_prop270_df$label == "c1", 11]


# Outcome = consistent voting
med_summary[5,1] <- "Climate : Time > DKs arguments > consistent vote"
med_summary[5,2] <- sumfit_climat0_df[sumfit_climat0_df$label == "days_dk_cons", 6]
med_summary[5,3] <- sumfit_climat0_df[sumfit_climat0_df$label == "days_dk_cons", 10]
med_summary[5,4] <- sumfit_climat0_df[sumfit_climat0_df$label == "days_dk_cons", 11]
med_summary[5,5] <- sumfit_climat0_df[sumfit_climat0_df$label == "c2", 6]
med_summary[5,6] <- sumfit_climat0_df[sumfit_climat0_df$label == "c2", 10]
med_summary[5,7] <- sumfit_climat0_df[sumfit_climat0_df$label == "c2", 11]

med_summary[6,1] <- "OECD : Time > DKs arguments > consistent vote"
med_summary[6,2] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "days_dk_cons", 6]
med_summary[6,3] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "days_dk_cons", 10]
med_summary[6,4] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "days_dk_cons", 11]
med_summary[6,5] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "c2", 6]
med_summary[6,6] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "c2", 10]
med_summary[6,7] <- sumfit_OCDE0_df[sumfit_OCDE0_df$label == "c2", 11]

med_summary[7,1] <- "Proposition 26 : Time > DKs arguments > consistent vote"
med_summary[7,2] <- sumfit_prop260_df[sumfit_prop260_df$label == "days_dk_cons", 6]
med_summary[7,3] <- sumfit_prop260_df[sumfit_prop260_df$label == "days_dk_cons", 10]
med_summary[7,4] <- sumfit_prop260_df[sumfit_prop260_df$label == "days_dk_cons", 11]
med_summary[7,5] <- sumfit_prop260_df[sumfit_prop260_df$label == "c2", 6]
med_summary[7,6] <- sumfit_prop260_df[sumfit_prop260_df$label == "c2", 10]
med_summary[7,7] <- sumfit_prop260_df[sumfit_prop260_df$label == "c2", 11]

med_summary[8,1] <- "Proposition 27 : Time > DKs arguments > consistent vote"
med_summary[8,2] <- sumfit_prop270_df[sumfit_prop270_df$label == "days_dk_cons", 6]
med_summary[8,3] <- sumfit_prop270_df[sumfit_prop270_df$label == "days_dk_cons", 10]
med_summary[8,4] <- sumfit_prop270_df[sumfit_prop270_df$label == "days_dk_cons", 11]
med_summary[8,5] <- sumfit_prop270_df[sumfit_prop270_df$label == "c2", 6]
med_summary[8,6] <- sumfit_prop270_df[sumfit_prop270_df$label == "c2", 10]
med_summary[8,7] <- sumfit_prop270_df[sumfit_prop270_df$label == "c2", 11]

med_summary

# Indirect
ind <- med_summary %>% dplyr::select(1:4)
glimpse(ind)

empty_row <- data.frame(effect = "", ind = NA, lowind = NA, uppind = NA)
ind <- rbind(ind[1:4, ], empty_row, ind[5:nrow(ind), ])
rownames(ind) <- NULL

ind

ind$effect <- factor(ind$effect, 
                     levels = c("Proposition 27 : Time > DKs arguments > consistent vote",
                                "Proposition 26 : Time > DKs arguments > consistent vote",
                                "OECD : Time > DKs arguments > consistent vote",
                                "Climate : Time > DKs arguments > consistent vote",
                                "",
                                "Proposition 27 : Time > knowledge party cue > vote inline", 
                                "Proposition 26 : Time > knowledge party cue > vote inline",
                                "OECD : Time > knowledge party cue > vote inline",
                                "Climate : Time > knowledge party cue > vote inline"),
                     ordered = T)

ind_plot <- ggplot(ind, aes(x = effect, y = ind)) + 
  geom_pointrange(aes(ymin = lowind, ymax = uppind), size = 0.25) +
  scale_y_continuous(limits = c(-0.06,0.45), breaks = seq(-0.05, 0.40, by = 0.10)) +
  geom_hline(yintercept = 0) +
  xlab("") + ylab("Estimate") + ggtitle("Indirect") +
  theme_minimal() +
  coord_flip()  

ind_plot

ggsave("indirect0.png", scale = 1, width = 18, height = 10, units = "cm", dpi = 600)





# Appendix C3b ----

# Empty dataframe
med_summary <- data.frame(matrix(ncol = 7, nrow = 8))
x <- c("effect", "ind", "lowind", "uppind", "dir", "lowdir", "uppdir")
colnames(med_summary) <- x

# Outcome = vote inline party cue
med_summary[1,1] <- "Climate : Time > knowledge party cue > vote inline"
med_summary[1,2] <- sumfit_climat5_df[sumfit_climat5_df$label == "days_cue_inline", 6]
med_summary[1,3] <- sumfit_climat5_df[sumfit_climat5_df$label == "days_cue_inline", 10]
med_summary[1,4] <- sumfit_climat5_df[sumfit_climat5_df$label == "days_cue_inline", 11]
med_summary[1,5] <- sumfit_climat5_df[sumfit_climat5_df$label == "c1", 6]
med_summary[1,6] <- sumfit_climat5_df[sumfit_climat5_df$label == "c1", 10]
med_summary[1,7] <- sumfit_climat5_df[sumfit_climat5_df$label == "c1", 11]

med_summary[2,1] <- "OECD : Time > knowledge party cue > vote inline"
med_summary[2,2] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "days_cue_inline", 6]
med_summary[2,3] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "days_cue_inline", 10]
med_summary[2,4] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "days_cue_inline", 11]
med_summary[2,5] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "c1", 6]
med_summary[2,6] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "c1", 10]
med_summary[2,7] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "c1", 11]

med_summary[3,1] <- "Proposition 26 : Time > knowledge party cue > vote inline"
med_summary[3,2] <- sumfit_prop265_df[sumfit_prop265_df$label == "days_cue_inline", 6]
med_summary[3,3] <- sumfit_prop265_df[sumfit_prop265_df$label == "days_cue_inline", 10]
med_summary[3,4] <- sumfit_prop265_df[sumfit_prop265_df$label == "days_cue_inline", 11]
med_summary[3,5] <- sumfit_prop265_df[sumfit_prop265_df$label == "c1", 6]
med_summary[3,6] <- sumfit_prop265_df[sumfit_prop265_df$label == "c1", 10]
med_summary[3,7] <- sumfit_prop265_df[sumfit_prop265_df$label == "c1", 11]

med_summary[4,1] <- "Proposition 27 : Time > knowledge party cue > vote inline"
med_summary[4,2] <- sumfit_prop275_df[sumfit_prop275_df$label == "days_cue_inline", 6]
med_summary[4,3] <- sumfit_prop275_df[sumfit_prop275_df$label == "days_cue_inline", 10]
med_summary[4,4] <- sumfit_prop275_df[sumfit_prop275_df$label == "days_cue_inline", 11]
med_summary[4,5] <- sumfit_prop275_df[sumfit_prop275_df$label == "c1", 6]
med_summary[4,6] <- sumfit_prop275_df[sumfit_prop275_df$label == "c1", 10]
med_summary[4,7] <- sumfit_prop275_df[sumfit_prop275_df$label == "c1", 11]


# Outcome = consistent voting
med_summary[5,1] <- "Climate : Time > DKs arguments > consistent vote"
med_summary[5,2] <- sumfit_climat5_df[sumfit_climat5_df$label == "days_dk_cons", 6]
med_summary[5,3] <- sumfit_climat5_df[sumfit_climat5_df$label == "days_dk_cons", 10]
med_summary[5,4] <- sumfit_climat5_df[sumfit_climat5_df$label == "days_dk_cons", 11]
med_summary[5,5] <- sumfit_climat5_df[sumfit_climat5_df$label == "c2", 6]
med_summary[5,6] <- sumfit_climat5_df[sumfit_climat5_df$label == "c2", 10]
med_summary[5,7] <- sumfit_climat5_df[sumfit_climat5_df$label == "c2", 11]

med_summary[6,1] <- "OECD : Time > DKs arguments > consistent vote"
med_summary[6,2] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "days_dk_cons", 6]
med_summary[6,3] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "days_dk_cons", 10]
med_summary[6,4] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "days_dk_cons", 11]
med_summary[6,5] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "c2", 6]
med_summary[6,6] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "c2", 10]
med_summary[6,7] <- sumfit_OCDE5_df[sumfit_OCDE5_df$label == "c2", 11]

med_summary[7,1] <- "Proposition 26 : Time > DKs arguments > consistent vote"
med_summary[7,2] <- sumfit_prop265_df[sumfit_prop265_df$label == "days_dk_cons", 6]
med_summary[7,3] <- sumfit_prop265_df[sumfit_prop265_df$label == "days_dk_cons", 10]
med_summary[7,4] <- sumfit_prop265_df[sumfit_prop265_df$label == "days_dk_cons", 11]
med_summary[7,5] <- sumfit_prop265_df[sumfit_prop265_df$label == "c2", 6]
med_summary[7,6] <- sumfit_prop265_df[sumfit_prop265_df$label == "c2", 10]
med_summary[7,7] <- sumfit_prop265_df[sumfit_prop265_df$label == "c2", 11]

med_summary[8,1] <- "Proposition 27 : Time > DKs arguments > consistent vote"
med_summary[8,2] <- sumfit_prop275_df[sumfit_prop275_df$label == "days_dk_cons", 6]
med_summary[8,3] <- sumfit_prop275_df[sumfit_prop275_df$label == "days_dk_cons", 10]
med_summary[8,4] <- sumfit_prop275_df[sumfit_prop275_df$label == "days_dk_cons", 11]
med_summary[8,5] <- sumfit_prop275_df[sumfit_prop275_df$label == "c2", 6]
med_summary[8,6] <- sumfit_prop275_df[sumfit_prop275_df$label == "c2", 10]
med_summary[8,7] <- sumfit_prop275_df[sumfit_prop275_df$label == "c2", 11]

med_summary

# Indirect
ind <- med_summary %>% dplyr::select(1:4)
glimpse(ind)

empty_row <- data.frame(effect = "", ind = NA, lowind = NA, uppind = NA)
ind <- rbind(ind[1:4, ], empty_row, ind[5:nrow(ind), ])
rownames(ind) <- NULL

ind

ind$effect <- factor(ind$effect, 
                     levels = c("Proposition 27 : Time > DKs arguments > consistent vote",
                                "Proposition 26 : Time > DKs arguments > consistent vote",
                                "OECD : Time > DKs arguments > consistent vote",
                                "Climate : Time > DKs arguments > consistent vote",
                                "",
                                "Proposition 27 : Time > knowledge party cue > vote inline", 
                                "Proposition 26 : Time > knowledge party cue > vote inline",
                                "OECD : Time > knowledge party cue > vote inline",
                                "Climate : Time > knowledge party cue > vote inline"),
                     ordered = T)

ind_plot <- ggplot(ind, aes(x = effect, y = ind)) + 
  geom_pointrange(aes(ymin = lowind, ymax = uppind), size = 0.25) +
  scale_y_continuous(limits = c(-0.06,0.45), breaks = seq(-0.05, 0.40, by = 0.10)) +
  geom_hline(yintercept = 0) +
  xlab("") + ylab("Estimate") + ggtitle("Indirect") +
  theme_minimal() +
  coord_flip()  

ind_plot

ggsave("indirect5.png", scale = 1, width = 18, height = 10, units = "cm", dpi = 600)









# Appendix C ----

# Empty dataframe
med_summary <- data.frame(matrix(ncol = 7, nrow = 8))
x <- c("effect", "ind", "lowind", "uppind", "dir", "lowdir", "uppdir")
colnames(med_summary) <- x

# Outcome = vote inline party cue
med_summary[1,1] <- "Climate : Time > knowledge party cue > vote inline"
med_summary[1,2] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "days_cue_inline", 6]
med_summary[1,3] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "days_cue_inline", 10]
med_summary[1,4] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "days_cue_inline", 11]
med_summary[1,5] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "c1", 6]
med_summary[1,6] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "c1", 10]
med_summary[1,7] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "c1", 11]

med_summary[2,1] <- "OECD : Time > knowledge party cue > vote inline"
med_summary[2,2] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "days_cue_inline", 6]
med_summary[2,3] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "days_cue_inline", 10]
med_summary[2,4] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "days_cue_inline", 11]
med_summary[2,5] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "c1", 6]
med_summary[2,6] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "c1", 10]
med_summary[2,7] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "c1", 11]

med_summary[3,1] <- "Proposition 26 : Time > knowledge party cue > vote inline"
med_summary[3,2] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "days_cue_inline", 6]
med_summary[3,3] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "days_cue_inline", 10]
med_summary[3,4] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "days_cue_inline", 11]
med_summary[3,5] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "c1", 6]
med_summary[3,6] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "c1", 10]
med_summary[3,7] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "c1", 11]

med_summary[4,1] <- "Proposition 27 : Time > knowledge party cue > vote inline"
med_summary[4,2] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "days_cue_inline", 6]
med_summary[4,3] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "days_cue_inline", 10]
med_summary[4,4] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "days_cue_inline", 11]
med_summary[4,5] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "c1", 6]
med_summary[4,6] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "c1", 10]
med_summary[4,7] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "c1", 11]


# Outcome = consistent voting
med_summary[5,1] <- "Climate : Time > DKs arguments > consistent vote"
med_summary[5,2] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "days_dk_cons", 6]
med_summary[5,3] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "days_dk_cons", 10]
med_summary[5,4] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "days_dk_cons", 11]
med_summary[5,5] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "c2", 6]
med_summary[5,6] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "c2", 10]
med_summary[5,7] <- sumfit_climatcertain_df[sumfit_climatcertain_df$label == "c2", 11]

med_summary[6,1] <- "OECD : Time > DKs arguments > consistent vote"
med_summary[6,2] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "days_dk_cons", 6]
med_summary[6,3] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "days_dk_cons", 10]
med_summary[6,4] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "days_dk_cons", 11]
med_summary[6,5] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "c2", 6]
med_summary[6,6] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "c2", 10]
med_summary[6,7] <- sumfit_OCDEcertain_df[sumfit_OCDEcertain_df$label == "c2", 11]

med_summary[7,1] <- "Proposition 26 : Time > DKs arguments > consistent vote"
med_summary[7,2] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "days_dk_cons", 6]
med_summary[7,3] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "days_dk_cons", 10]
med_summary[7,4] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "days_dk_cons", 11]
med_summary[7,5] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "c2", 6]
med_summary[7,6] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "c2", 10]
med_summary[7,7] <- sumfit_prop26certain_df[sumfit_prop26certain_df$label == "c2", 11]

med_summary[8,1] <- "Proposition 27 : Time > DKs arguments > consistent vote"
med_summary[8,2] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "days_dk_cons", 6]
med_summary[8,3] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "days_dk_cons", 10]
med_summary[8,4] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "days_dk_cons", 11]
med_summary[8,5] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "c2", 6]
med_summary[8,6] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "c2", 10]
med_summary[8,7] <- sumfit_prop27certain_df[sumfit_prop27certain_df$label == "c2", 11]

med_summary


# Indirect
ind <- med_summary %>% dplyr::select(1:4)
glimpse(ind)

empty_row <- data.frame(effect = "", ind = NA, lowind = NA, uppind = NA)
ind <- rbind(ind[1:4, ], empty_row, ind[5:nrow(ind), ])
rownames(ind) <- NULL

ind

ind$effect <- factor(ind$effect, 
                     levels = c("Proposition 27 : Time > DKs arguments > consistent vote",
                                "Proposition 26 : Time > DKs arguments > consistent vote",
                                "OECD : Time > DKs arguments > consistent vote",
                                "Climate : Time > DKs arguments > consistent vote",
                                "",
                                "Proposition 27 : Time > knowledge party cue > vote inline", 
                                "Proposition 26 : Time > knowledge party cue > vote inline",
                                "OECD : Time > knowledge party cue > vote inline",
                                "Climate : Time > knowledge party cue > vote inline"),
                     ordered = T)

ind_plot <- ggplot(ind, aes(x = effect, y = ind)) + 
  geom_pointrange(aes(ymin = lowind, ymax = uppind), size = 0.25) +
  scale_y_continuous(limits = c(-0.06,0.52), breaks = seq(-0.05, 0.40, by = 0.10)) +
  geom_hline(yintercept = 0) +
  xlab("") + ylab("Estimate") + ggtitle("Indirect") +
  theme_minimal() +
  coord_flip()  

ind_plot

ggsave("indirectcertainlikely.png", scale = 1, width = 18, height = 10, units = "cm", dpi = 600)






